#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

typedef struct Node {
    int data;
    struct Node *next;
} Node;

Node *initQueue() 
{
    Node *Q = (Node *)malloc(sizeof(Node));
    Q->data = 0;
    Q->next = NULL;
    return Q;
}

int isEmpty(Node *Q)
{
    if (Q->data == 0 || Q->next == NULL) return true;
    return false;
}

void enQueue(Node *Q, int data) 
{
    Node *node = (Node *)malloc(sizeof(Node));
    node->data = data;
    Node *tmp = Q;
    for (int i = 0; i < Q->data; i++) {
        tmp = tmp->next;
    }
    node->next = NULL;//即tmp->next;
    tmp->next = node;
    Q->data++;
}

int deQueue(Node *Q) 
{
    if (isEmpty(Q)) return -1;
    Node *del = Q->next;
    int data = del->data;
    Q->next = del->next;
    free(del);
    Q->data--;
    return data;
}

void printQueue(Node *Q) 
{
    Node *tmp = Q->next;
    while (tmp) {
        printf("%d->", tmp->data);
        tmp = tmp->next;
    }
    printf("NULL\n");
}

int main(void)
{
    Node *Q = initQueue();
    enQueue(Q, 1);
    enQueue(Q, 2);
    enQueue(Q, 3);
    enQueue(Q, 4);
    deQueue(Q);
    printQueue(Q);
    deQueue(Q);
    printQueue(Q);


    return 0;
}